define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'article/index',
                    add_url: 'article/add',
                    edit_url: 'article/edit',
                    del_url: 'article/del',
                    multi_url: 'article/multi',
                    table: 'article',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        //{field: 'site_id', title: __('Site_id')},
                        {field: 'cate_name', title: __('Site_id_text'), operate:false},
                        {field: 'name', title: __('Name')},
                        //{field: 'littitle', title: __('Littitle')},
                        //{field: 'litpic', title: __('Litpic')},
                        //{field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag},
                        //{field: 'source', title: __('Source')},
                        //{field: 'publish', title: __('Publish')},
                        //{field: 'is_jump', title: __('Is_jump')},
                        //{field: 'author', title: __('Author')},
                        //{field: 'jumpurl', title: __('Jumpurl'), formatter: Table.api.formatter.url},
                        //{field: 'summary', title: __('Summary')},
                        //{field: 'province', title: __('Province')},
                        //{field: 'city', title: __('City')},
                        //{field: 'area', title: __('Area')},
                        {field: 'hits', title: __('Hits')},
                        {field: 'status', title: __('Status'), formatter: Controller.api.formatter.status},
                        //{field: 'comment', title: __('Comment')},
                        //{field: 'is_comment', title: __('Is_comment')},
                        //{field: 'user_id', title: __('User_id')},
                        {field: 'addtime', title: __('Addtime'),formatter: Table.api.formatter.datetime,operate:false},
                        //{field: 'addip', title: __('Addip')},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                status: function (value, row, index) {
                    if(value==1){
                        return "开启";
                    }else{
                        return '隐藏';
                    }
                },
            },
        }
    };
    return Controller;
});